﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;

namespace wallstreet
{
    public partial class Control_News_View : PhoneApplicationPage
    {
        public Control_News_View()
        {
            InitializeComponent();
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            this.BackKeyPress += new EventHandler<System.ComponentModel.CancelEventArgs>(MainPage_BackKeyPress);

            if (IsolatedStorageSettings.ApplicationSettings.Contains("NewsFeed"))
            {
                NewsFeed feed = IsolatedStorageSettings.ApplicationSettings["NewsFeed"] as NewsFeed;

                if (feed != null && feed.Link != "")
                {
                    webbrowser.Navigate(new Uri(feed.Link));
                    webbrowser.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(webbrowser_LoadCompleted);
                }
            }
        }

        void webbrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            webbrowser.Visibility = Visibility.Visible;
            lblLoading.Visibility = Visibility.Collapsed;
        }

        void MainPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
        {
            NavigationService.GoBack();
        }

        private void btnBack_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            NavigationService.GoBack();
        }
    }
}